/***********************************************************************
	filename: 	D4YsXMLParser.h
	created:	18/4/2012
	author:		4Ys
	
	purpose:	Defines classes of XMLParser with TinyXML.	            
*************************************************************************/
#ifndef _4YsXMLParser_h_
#define _4YsXMLParser_h_

#include "tinyxml.h"
#include "tinystr.h"

#include <string>
#include <vector>

namespace Dater
{
	/*! 
	\brief
		A abstract class used by dater to parse xml file from local folder.
	*/
	class XMLParser
	{
	public:
		/*!
			Construction of XMLParser.
		*/
		XMLParser();

		/*!
			Destructor of XMLParser
		*/
		~XMLParser();

		/*!
		\brief
			Create an xml file.

		\return
			- true : create successfully.
			- false : create fail.
		*/
		bool createXmlFile();

		
		/*!
		\brief
			Drop an xml file.
		*/
		void dropXmlFile();

		/*!
		\brief
			Read an xml file.

		\return 
			- true : read successfully.
			- false : read fail.
		*/
		virtual bool readXmlFile() = 0;

		/*!
		\brief
			Save an xml file.

		\return 
			- true : save successfully.
			- false : save fail.
		*/
		virtual bool saveXmlFile() = 0;

		/*!
		\brief
			Set path of the app.

		\param apppath
			- a string means path of the app.

		\return
			Nothing.
		*/
		void setAppPath(std::string apppath){_appPath = apppath;}

		/*!
		\brief
			Get the value of appPath.

		\return
			appPath.
		*/
		std::string getAppPath(){return _appPath;}

		/*!
		\brief
			Get the pointer of myXml.

		\return
			A pointer of myXml
		*/
		TiXmlDocument* getMyXml(){return _myXml;}
		
		/*!
		\brief
			Get the value of xmlName.

		\return
			className.
		*/
		std::string getClassName(){return _className;}

		/*!
		\brief
			Set name of the xml.

		\param xmlname
			- a string means name of the xml.

		\return
			Nothing.
		*/
		void setXmlName(std::string xmlname){_xmlName = xmlname;}

		/*!
		\brief
			Get the value of xmlName.

		\return
			xmlName.
		*/
		std::string getXmlName(){return _xmlName;}

	protected:
		/*!
			a pointer to TiXmlDocument to save the path to the file operated.
		*/
		TiXmlDocument* _myXml;

		/*!
			a string means path of the app.
		*/
		std::string _appPath;

		/*!
			a string means name of the xml.
		*/
		std::string _xmlName;

		/*!
			a string means name of the class.
		*/
		std::string _className;

		/*!
		\brief
			Create an element in one node of the xml file.

		\param element
			- a pointer to TiXmlElement which stands for an element of the node in an xml file.

		\param elementName
			- a string stores the name of the element

		\param elementValue
			- a string stores the value of the element.

		\return
			Nothing.
		*/
		void createElement(TiXmlElement* element, std::string elementName, std::string elementValue);

				/*!
		\brief
			Split the string stands for Time.

		\param order
		     - a string of order from client to server.

		 \param delimiter
		     - a string which is the charactor to split the order.

		 \param splitedVector
		     - a vector of strings which are tiny orders splited from order.

		 \return
			 Nothing.
		*/
		void split(std::string const& order, std::string delimiter, std::vector<std::string>& splitedVector);
	};

}

#endif